package com.lgx.mobile.dao.impl;

import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.lgx.common.basic.dao.GeneralDao;
import com.lgx.common.exception.DataException;
import com.lgx.mobile.dao.IGiftRecordDao;
import com.lgx.mobile.entity.GiftRecord;

/**
 * 
 * @author xuyichen
 *
 */
@Component("giftRecordDao")
public class GiftRecordDao extends GeneralDao implements IGiftRecordDao {

	protected Logger log = Logger.getLogger(this.getClass());
	
	public GiftRecord createGiftRecord(GiftRecord giftRecord) throws DataException {
		this.getHibernateTemplate().save(giftRecord);
		log.info("[创建礼品赠送记录]:"+giftRecord.getId());
		return giftRecord;
	}

	public GiftRecord updateGiftRecord(GiftRecord giftRecord) throws DataException {
		this.getHibernateTemplate().update(giftRecord);
		log.info("[更新礼品赠送记录]:"+giftRecord.getId());
		return giftRecord;
	}

	public void deleteGiftRecord(GiftRecord giftRecord) throws DataException {
		log.info("[删除礼品赠送记录]:"+giftRecord.getId());
		this.getHibernateTemplate().delete(giftRecord);
	}

	public void deleteGiftRecordById(long id) throws DataException {
		log.info("[删除礼品赠送记录]:"+id);
		this.deleteGiftRecord(this.findGiftRecordById(id));
	}

	public GiftRecord findGiftRecordById(long id) {
		return this.getHibernateTemplate().get(GiftRecord.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<GiftRecord> findGiftRecordList(){
		String sql = "from GiftRecord gr order by gr.id asc";
		return this.getHibernateTemplate().find(sql);
	}
}
